package org.kjk;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


@SuppressWarnings("serial")
public class JSonTest extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		JSONObject jObj = new JSONObject();
		JSONArray arrayObj = new JSONArray();
		try {
			jObj.put("users", arrayObj);
			for (int i = 1; i <= 6; i++) {
				JSONObject obj1 = new JSONObject();
				obj1.put("id", i);
				obj1.put("firstName", "data" + i + "-1");
				obj1.put("lastName", "data" + i + "-2");
				arrayObj.put(obj1);
			}
//			jObj.put("hello", "hello");
//			arrayObj.put("MCA");
//			arrayObj.put("Amit Kumar");
//			arrayObj.put("19-12-1986");
//			arrayObj.put(24);
//			arrayObj.put("Scored");
//			arrayObj.put(new Double(66.67));
//			jObj.put("arr", arrayObj);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		PrintWriter out = resp.getWriter();
		out.println(jObj);
//		Iterator it = jObj.keys();
//		while (it.hasNext()) {
//			out.println(it.next());
//		}
		out.flush();
		out.close();
	}
}
